<template>
  <div class="login">
    <div class="denglu">密码登录</div>
    <div class="phone">
      <input type="text" placeholder="手机/用户名" v-model="phone" />
    </div>
    <div class="password">
      <input type="password" placeholder="密码" v-model="pass" />
    </div>
    <div class="btn" @click="handleClick()">登录</div>

    <div class="msg">
      <span @click="zhuceClick()">去注册</span>
      <span>忘记密码</span>
    </div>
    <div class="xieyi">
      <input type="checkbox" name="" id="" />
      <span>已阅读并同意《用户服务协议》、《隐私政策》</span>
    </div>
  </div>
</template>

<script>
import { login } from "../api/index";
export default {
  data() {
    return {
      phone: "",
      pass: "",
    };
  },
  methods: {
    handleClick() {
      login({ phone: this.phone, pass: this.pass }).then((res) => {
        console.log(res.data);
        if (res.data.code == 200) {
          alert("登陆成功");
          localStorage.setItem('token',res.data.token)
          this.$router.push("/");
        } else {
          alert("请输入正确的手机号和密码");
        }
        localStorage.setItem('userinfo',JSON.stringify(res.data.userinfo))//将对象形式的数据转换成字符串形式并保存到本地
      });
    },
    zhuceClick() {
      this.$router.push("/register");
    },
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
input,
button {
  border: 0;
  outline: none;
}
.login {
  margin: 60px auto;
  width: 360px;
  height: 700px;
  padding: 20px;
  border: 1px solid gray;
  border-radius: 10px;
}
.login .denglu {
  margin-top: 60px;
  font-size: 26px;
  margin-bottom: 20px;
}
.login .phone {
  border-bottom: 1px solid gray;
  margin-bottom: 20px;
  height: 30px;
}
.login .password {
  border-bottom: 1px solid gray;
  margin-bottom: 20px;
  height: 30px;
  margin-bottom: 30px;
}
.login .btn {
  width: 100%;
  height: 30px;
  border-radius: 20px;
  background-color: #ccc;
  text-align: center;
  line-height: 30px;
  color: gray;
  font-size: 14px;
}
.login .msg {
  margin-top: 10px;
  color: rgb(85, 180, 231);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}
.login .xieyi {
  margin-top: 360px;
  font-size: 14px;
}
</style>